package com.ruoyi.store.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.store.domain.TbTable;
import com.ruoyi.store.service.ITbTableService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 餐桌Controller
 *
 * @author ruoyi
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/table")
public class TbTableController extends BaseController {
    @Autowired
    private ITbTableService tbTableService;

    /**
     * 查询餐桌列表
     */
   // @RequiresPermissions("store:table:list")
    @GetMapping("/list")
    public TableDataInfo list(TbTable tbTable) {
        startPage();
        List<TbTable> list = tbTableService.selectTbTableList(tbTable);
        return getDataTable(list);
    }

    /**
     * 导出餐桌列表
     */
    @RequiresPermissions("store:table:export")
    @Log(title = "餐桌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTable tbTable) {
        List<TbTable> list = tbTableService.selectTbTableList(tbTable);
        ExcelUtil<TbTable> util = new ExcelUtil<TbTable>(TbTable.class);
        util.exportExcel(response, list, "餐桌数据");
    }

    /**
     * 获取餐桌详细信息
     */
    @RequiresPermissions("store:table:query")
    @GetMapping(value = "/{tableId}")
    public AjaxResult getInfo(@PathVariable("tableId") Long tableId) {
        return success(tbTableService.selectTbTableByTableId(tableId));
    }

    /**
     * 新增餐桌
     */
    @RequiresPermissions("store:table:add")
    @Log(title = "餐桌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTable tbTable) {
        return toAjax(tbTableService.insertTbTable(tbTable));
    }

    /**
     * 修改餐桌
     */
    @RequiresPermissions("store:table:edit")
    @Log(title = "餐桌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTable tbTable) {
        return toAjax(tbTableService.updateTbTable(tbTable));
    }

    /**
     * 删除餐桌
     */
    @RequiresPermissions("store:table:remove")
    @Log(title = "餐桌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tableIds}")
    public AjaxResult remove(@PathVariable Long[] tableIds) {
        return toAjax(tbTableService.deleteTbTableByTableIds(tableIds));
    }


}
